package com.onpositive.gamemaker.swt;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.graphics.Region;
import org.eclipse.swt.widgets.Display;

import com.onpositive.gamemaker.core.GraphicDevice;
import com.onpositive.gamemaker.visualizer.HexagonMath;

public class SWTGraphicsDevice extends GraphicDevice
{

	private final GC gc;

	public SWTGraphicsDevice(GC gc)
	{
		this.gc = gc;
	}

	@Override
	public void drawHexImage(String imageId, int x, int y, int width, int height)
	{
		Image image = SWTImageManager.getImage(imageId);
		int[] clipArray = HexagonMath.getHexagonCoordArray(x, y, width / 2);
		Region region = new Region();
		region.add(clipArray);
		gc.setClipping(region);
		gc.drawImage(image,x,y);
		region.dispose();
	}

	@Override
	public void drawHexGrid(int x, int y, int radius)
	{
		int[] clipArray = HexagonMath.getHexagonCoordArray(x, y, radius);
		gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLUE));
		gc.drawPolygon(clipArray);
	}

	@Override
	public void drawImage(String imageId, int x, int y, int width, int height)
	{
		gc.setClipping((Rectangle)null);
		Image image = SWTImageManager.getImage(imageId,true);
		gc.drawImage(image,x,y);
	}

}
